//
//  NSString+DateFormat.m
//  RentTable
//
//  Created by mac on 2024/11/30.
//

#import "NSString+DateFormat.h"

@implementation NSString (DateFormat)

+ (NSString *)currentDateString {
    NSDate *currentDate = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *dateString = [formatter stringFromDate:currentDate];
    return dateString;
}

+ (NSString *)currentOrderDateString {
    NSDate *currentDate = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSString *dateString = [formatter stringFromDate:currentDate];
    return dateString;
}

+ (NSString *)dateByAddingMonthsToDate:(NSString *)dateString months:(NSInteger)months {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    
    NSDate *inputDate = [formatter dateFromString:dateString];
    
    if (!inputDate) {
        return @"Invalid Date";
    }
    
    NSCalendar *calendar = [NSCalendar currentCalendar];
    
    NSDate *newDate = [calendar dateByAddingUnit:NSCalendarUnitMonth value:months toDate:inputDate options:0];
    
    NSString *newDateString = [formatter stringFromDate:newDate];
    
    return newDateString;
}

@end
